import sys
import os

thisDir = os.path.split(os.path.realpath(__file__))[0]
sys.path.append(os.path.join(thisDir, "pu"))
sys.path.append(os.path.join(thisDir, "..", "server"))
sys.path.append(os.path.join(thisDir, "..", "common"))

import EJOConst

from PU import PU
from EJOServerInitializer import EJOServerInitializer
from SessionManager import SessionManager

import logging
logger = logging.getLogger(__name__)

class EJOUiInitializer(EJOServerInitializer):
    def __init__(self):
        logger.debug("[EJOUiInitializer.EJOUiInitializer]")
        super().__init__()

    def Initialize(self):
        logger.debug("[EJOUiInitializer.Initialize]")
        return self.__initUI()

    def __initUI(self):
        configPath = os.path.join(thisDir, "EJOUi.py")
        schemaDir = os.path.join(thisDir, "..", "schema")
        pu = PU(configPath, schemaDir)
        if not pu:
            logger.error("PU load failed")
            return False
        SessionManager().SetProperty(EJOConst.SESSION_PROPERTY_UI, pu)
        return True
